Ext.namespace("GridAuthInfo");
GridAuthInfo.Detail = function() {
	this.userSelector = null;
	this.selectedIds="";
	this.selectedIdsName="";
	this.selectedRoles="";
	this.selectedRolesName="";
	//社区id
	this.txtGridAuthId = new Ext.form.Hidden();//记录id
    this.cmbLevel=new Ext.form.ComboBox({
		fieldLabel : '访问级别<font color="red">*</font> ',
		width : 150,
        store: OMS.GRID_LEVEL,
        //editable: false,
        allowBlank:false,
        typeAhead:true,
        mode: 'local',
        triggerAction: 'all',
        emptyText:'请选择级别',
        listeners:{
          	scope: this,
	        	'select': this.changeAuth//联动的listener
      	},
        selectOnFocus: true	
	});
	
	this.txtAuth = new Ext.form.TextField({
		fieldLabel: '功能名称<font color="red">*</font> ',
		readOnly: true,
		width: 150,
		allowBlank:false,
		listeners: {
			   'render': function(cmp) {
					var self = cmp.ownerCt.ownerCt.ownerCt;
					cmp.getEl().on('click', function(){ 
						if(this.cmbLevel.getValue()==1||this.cmbLevel.getValue()==2||this.cmbLevel.getValue()=="") self.showUser1();
					}, self); 
				}					
			}
	});
	this.txtRole = new Ext.form.TextField({
		fieldLabel: '角色名称<font color="red">*</font> ',
		readOnly: true,
		allowBlank:false,
		width: 150,
		listeners: {
			   'render': function(cmp) {
					var self = cmp.ownerCt.ownerCt.ownerCt;
					cmp.getEl().on('click', function(){
							if(this.cmbLevel.getValue()==1||this.cmbLevel.getValue()==2||this.cmbLevel.getValue()=="") self.showUser2();
						}
					, self); 
				}					
			}
	});
	//基本信息
	this.form = new Ext.form.FormPanel({
		bodyStyle : 'padding: 5px 5px 0',
		frame :true,
		//fileUpload: true, 
		autoScroll : true,
		//autoHeight : true,
		labelAlign: 'right',
		labelWidth : 150,
		layout : 'table',
		layoutConfig : {columns:1},
		items:[
			{layout:'form',items:[this.txtRole]},
			{layout:'form',items:[this.cmbLevel]},
			{layout:'form',items:[this.txtAuth]},
			{layout:'form',items:[this.txtGridAuthId]}
		]
	});
	GridAuthInfo.Detail.superclass.constructor.call(this,{
		title : '网格功能树',
		bodyStyle: 'padding: 5px 5px 0',
        autoHeight: true,
        width: 430,
        resizable: false,
        plain: true,
        modal: true,
        autoScroll: true,
        closeAction: 'hide',
        items :[this.form],
        buttons: [{
            text: '保存',
            cls: 'x-btn-text-icon btn-save',
            handler: this.onSave,
            scope: this
        }, {
            text: '关闭',
            cls: 'x-btn-text-icon btn-cancel',
            handler: this.hide.createDelegate(this, [])
        }]
		
	});
};

Ext.extend(GridAuthInfo.Detail,Ext.Window,{
		initAdd :function(){
			this.form.getForm().reset();
		},
		initEdit : function(data){
			this.txtGridAuthId.setValue(data.GRID_AUTH_ID);
			this.cmbLevel.setValue(data.AUTH_LEVEL);
			this.txtAuth.setValue(data.ENTITY_NAME);
			this.txtRole.setValue(data.ROLE_NAME);
			this.selectedIds=data.ENTITY_ID;
			this.selectedRoles=data.ROLE_ID;
			//this.cmbRoleName.setValue(data.ROLE_ID);
		},
		changeAuth:function(){
			this.txtAuth.setValue('');
			//this.txtRole.setValue('');
			if(this.cmbLevel.getValue()==0){
				this.txtAuth.setValue('东区分公司');
				this.selectedIds="1";
				this.selectedIdsName="东区分公司";
			}
		},
		setIds: function(nodeIds,nodeTexts) {	// for Selector.User callback
			this.selectedIds=nodeIds;
			this.selectedIdsName=nodeTexts;
			this.txtAuth.setValue(nodeTexts);
		},
		showUser1:function(){
			var scope=this;
			//if(GridTree.list.instance==null){
				GridTree.list.instance =new GridTree.list(this,this.selectedIds);
			//}
			GridTree.list.instance.init(this.selectedIds);
			GridTree.list.instance.show();
		},
		setIds1: function(nodeIds,nodeTexts) {	// for Selector.User callback
			this.selectedRoles=nodeIds;
			this.selectedRolesName=nodeTexts;
			this.txtRole.setValue(nodeTexts);
		},
		showUser2:function(){
			var scope=this;
			if(BranchTree.list.instance==null){
				BranchTree.list.instance =new BranchTree.list(this,this.selectedRoles);
			}
			BranchTree.list.instance.init(this.selectedRoles);
			BranchTree.list.instance.show();
		},
		onSave:function(){
			if(!this.form.getForm().isValid()){
				Utils.info("信息填写不完整或有误,请检查!","系统提示");
				return;
			}
			this.conn =new Ext.data.Connection({
		        method: 'POST',
		        url: '../gridauth/save.form?timesnap=' + Date.parse(new Date())
		    });
			Utils.request(this.conn,{
				scope: this,
				params: {
					//基本信息
					grid_auth_id:this.txtGridAuthId.getValue(),					
					role_id :this.selectedRoles,
					role_name:this.selectedRolesName,
					entity_id :this.selectedIds.toString(),
					entity_name:this.selectedIdsName.toString(),
					auth_level :this.cmbLevel.getValue()
				},
				success:function(resp){	
					this.scope.hide();
					GridAuthInfo.List.instance.store.reload();
				}
			});
		}
});  